package com.huopaolan.yohuoshop.Mvc.View.helper;

import android.content.Intent;
import android.graphics.Color;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.ImageView;

import com.huopaolan.lib_core.Base.BaseActivity;
import com.huopaolan.yohuoshop.Mvp.View.Activity.HomeActivity;
import com.huopaolan.yohuoshop.R;

public class HelperActivity extends BaseActivity implements OnClickListener {
    private ImageView helper;
    private Button cancel_Button;
    private AnimationSet animatorSet;

    @Override
    public int layoutID() {
        return R.layout.activity_helper;
    }

    @Override
    public void initView() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        helper = findViewById(R.id.helper_image);
        cancel_Button = findViewById(R.id.cancel_action);
        cancel_Button.setOnClickListener(this);
        ScaleAnimaSet();
    }

    private void ScaleAnimaSet() {
        animatorSet = new AnimationSet(true);
        ScaleAnimation scaleAnimation = new ScaleAnimation(1.15f, 1.0f, 1.15f, 1.0f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnimation.setDuration(5000);//动画持续效果
        animatorSet.addAnimation(scaleAnimation);//保存动画
        animatorSet.setFillAfter(true);
        helper.startAnimation(animatorSet);
    }

    @Override
    public void onStart() {
        Window window = getWindow();
        window.setStatusBarColor(Color.BLACK);
        super.onStart();
    }

    @Override
    public void initData() {

    }

    @Override
    public void setUpDagger() {

    }

    @Override
    public void showDialog() {

    }

    @Override
    public void hideDialog() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.cancel_action:
                cancel_Button.setVisibility(View.GONE);
                CancelAnima();
                new Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        startActivity(new Intent(HelperActivity.this, HomeActivity.class));
                        finish();
                    }
                }, 2000);
                break;
        }
    }

    private void CancelAnima() {
        animatorSet.setFillAfter(false);
        animatorSet.cancel();
    }
}
